package com.zy.explore.generator;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * description 应用启动入口类
 *
 * @author 🇨🇳中国印🇨🇳
 * @date 2022年01月15日 16:31:23
 */
@Slf4j
@EnableDiscoveryClient
@SpringBootApplication
@EnableFeignClients(basePackages = {"com.zy.explore.generator.*"})
public class ZyGeneratorApplication {

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(ZyGeneratorApplication.class, args);

        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        if (StringUtils.isEmpty(path)) {
            path = "";
        }
        log.info("\n-------------------------------------------------------------------------------\n" +
                "ZyGeneratorApplication is running! Access URLs:\n\t" +
                "Local访问网址: \t\thttp://localhost:" + port + path + "\n\t" +
                "External访问网址: \thttp://" + ip + ":" + port + path + "\n\t" +
                "Swagger访问网址: \thttp://localhost:" + port + path + "/doc.html\n\n\n" +


                "注意：使用此生成器生成的代码，如想无缝对接项目(直接放入项目中不会报错可运行)，\n" +
                "则需要使用祝印的项目生成平台生成的项目。访问地址：http://zyexplore.sh1.k9s.run/\n" +
                "\n" +
                "1.不要擅自挪动目录结构\n\n" +
                "2.点击startup.bat，运行成功后可以看到日志最下方的swagger访问地址\n" +
                "  将swagger访问地址输入浏览器中访问\n\n" +
                "3.选择生成代码接口(唯一一个接口)，按自己的实际情况填写参数\n\n" +
                "4.点击发送，则可以看到生成结果信息。生成的代码放在填写的 codeRoot 参数值目录下\n\n" +
                "温馨提示：首次创建项目若将 codeRoot 直接设置成项目所在路径，则代码生成后直接在\n" +
                "项目里面，无需再手动复制粘贴。\n" +
                "-------------------------------------------------------------------------------\n");
    }

}